﻿
import YouHP.Graphics.*;

class SingleSymptom extends SingleChartBase
{
	function SingleSymptom(lv : Object)
    {
		mClip = _root.createEmptyMovieClip("SingleSymptom", _root.getNextHighestDepth());
        mData = lv;		
        
		//提取疾病图表公用信息
        ParseBase(lv); 
		//提取症状图表所需要的私有信息
        ParsePrivateData();
		
		//设置图例数据
		SetLegendData();
		
		//画图
        Draw();
	}
	
	private function ParsePrivateData()
	{
		mChartHeight = 70 ;
	}
	
	private function SetLegendData()
	{
		//数组中内容分别代表：症状程度， 症状程度颜色， 症状变化线的高度
        mLegendOption.push(["无", 0x008844, 20]);		
        mLegendOption.push(["轻度", 0xF1D827, 20]);		
        mLegendOption.push(["中度", 0xFF8A15, 20]);		
        mLegendOption.push(["重度", 0xC60000, 20]);		
	}
    
    private function Draw()
    {
		//画图例
        DrawLegend();
		
		//画网格线以及坐标值
		DrawGrid();

		//画图表数据
        DrawData();        
    } 
	     
    public function DrawLegend()
    {
      	var mc : MovieClip = mClip;
        var gs:Graphics = new Graphics(mClip);
        var pen = new Pen(1.0,0x0000cc,100);
		var brush = new SolidBrush(0x000000, 100);
        var startx = mLegendLeft;
        var y = mLegendTop;

		for(var i=0; i < mLegendOption.length; i++)
		{
			brush.setColor(mLegendOption[i][1]);
			gs.FillRect(brush, startx + 10, y, 12, 12);
			gs.DrawRect(pen, startx + 10, y, 12, 12);
	
			var label:TextField = mc.createTextField("option_" + i ,mc.getNextHighestDepth(),
				startx + 25, y-3, 0, 0);
			var myformat = new TextFormat();
			myformat.color = 0xff0000;
			myformat.align = "left";
			label.setTextFormat(myformat);
			
			label.html = true;
			label.autoSize = "left";
			label.htmlText = mLegendOption[i][0];

			startx = (i+1)*mLegendWidth ;
		}		
    }

    public function DrawGrid()
    {
       	var mc : MovieClip = mClip;
        var gs:Graphics = new Graphics(mClip);		
		var tmpColor:Number = 0xA0A0FF;
		var gridPen = new Pen(1.0, tmpColor,100);
		
		//画网格的矩形边框
		gridPen.setThickness(2);
		gs.DrawRect(gridPen, mChartLeft, mChartTop, mChartRight - mChartLeft, mChartHeight);
		
		SetXCoordinate(mDosageDate, mUpdateDate);
		for(var i=1; i<mChartXCount; i++)
		{
			if(i%4 != 0)
			{
				gridPen.setThickness(0.5);
				gs.DrawDashLine(gridPen, mChartLeft + i*mChartXGap, mChartTop, mChartLeft + i*mChartXGap, mChartTop + mChartHeight, 1, 1);
			}
			else
			{
				gridPen.setThickness(2);
				gs.DrawLine(gridPen, mChartLeft + i*mChartXGap, mChartTop, mChartLeft + i*mChartXGap, mChartTop + mChartHeight);
			}
		}
		
		//画坐标值
		for(i=0; i<mChartCoordinate.length; i++)
		{
			DrawText(mChartCoordinate[i][0], mChartLeft + (i+1)*mChartXGap*4, mChartTop + mChartHeight + 10, mDefaultColor, 10, "right");
		}		
    }
	
	private function DrawPoint(pen:Pen, brush:SolidBrush, x:Number, y:Number, width:Number, height:Number, value:String, pointCnt:Number)
	{
		var mc:MovieClip = _root.createEmptyMovieClip( "Tip_" + pointCnt, _root.getNextHighestDepth() );
		var gs:Graphics = new Graphics(mc);		
		var link:String = "" ;	//对应的超链接
		
		mc.ToolTip(value, link);
	
		gs.DrawRect(pen, x, y, width, height);
		gs.FillRect(brush, x, y, width, height);		
		
		this.mChildmcArr.push(mc);
	}	
	
    public function DrawData()
    {
       	var mc : MovieClip = mClip;
        var gs:Graphics = new Graphics(mc);		
		var pen = new Pen(1.0,0x0000cc,100);		
		var brush = new SolidBrush(0x0000cc, 100);
		
		var varArr = mData["Var"].split(";");
		var dataCnt : Number = varArr[1];
		var dataArr;
		var lastX = 0, curX = 0;
		var lastVal = -1, curVal = -1;
		var cnt = 0;
		var tmpStr:String, lastDate:String;
		
		for(var i=0; i<dataCnt; i++)
		{
			dataArr = mData["Data_" + i].split(";");
			curX = GetXMigration(Utils.StrToDate(dataArr[0]));										
			curVal = dataArr[1];
			
			//画矩形连线
			if(lastX > 0)
			{
				tmpStr = "起始时间：" + lastDate + "\n" + mLegendOption[lastVal][0] ;				
				DrawPoint(pen, brush, lastX, mChartTop + (mChartHeight - mLegendOption[lastVal][2])/2.0, curX - lastX, mLegendOption[lastVal][2],
							tmpStr, cnt++);
			}
			pen.setColor(mLegendOption[curVal][1]);
			brush.setColor(mLegendOption[curVal][1]);			
			
			lastX = curX ;
			lastVal = curVal;
			lastDate = dataArr[0];
		}
		
		//画最后一段
		tmpStr = "起始时间：" + lastDate + "\n" + mLegendOption[lastVal][0] ;				
		if(Utils.GetDayNumber(Utils.StrToDate(dataArr[0]), mUpdateDate) == 0)
		{
			DrawPoint(pen, brush, lastX, mChartTop + (mChartHeight - mLegendOption[lastVal][2])/2.0, mChartRight - lastX, mLegendOption[lastVal][2],
							tmpStr, cnt++);
		}
		else
		{
			DrawPoint(pen, brush, lastX, mChartTop + (mChartHeight - mLegendOption[lastVal][2])/2.0, mChartLeft + mChartWidth - lastX, mLegendOption[lastVal][2],
							tmpStr, cnt++);
		}
    }  	
}